package com.jayanslow.lighting.server.parser;

import java.math.BigInteger;


import com.jayanslow.lighting.protocol.misc.Bytes;
import com.jayanslow.lighting.protocol.misc.CharacterEncoding;
import com.jayanslow.lighting.server.clients.Client;
import com.jayanslow.lighting.server.dmx.DmxController;


public class Command {
	String cmd;
	Client client;
	
	public Command(Client client, String cmd) {
		this.cmd = cmd;
		this.client = client;
	}
	public String getCmd() {
		return cmd;
	}
	public Client getClient() {
		return client;
	}
	public void run(DmxController dmx) {
		BigInteger big = CharacterEncoding.CHAR128.decode(cmd);
		short[] input = Bytes.toBytes(big);
		short[] reply = CommandParser.startParse(dmx, client, input);
		big = Bytes.toBigInteger(reply);
		String s = CharacterEncoding.CHAR128.encode(big);
		client.println(s);
	}
}
